From: Florian Müllner Date: Sat, 28 Mar 2020 01:54:14 +0000 (+0100) Subject: dateMenu: Only use nearest city when appropriate X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~751^2^2~22 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=de16fe8dff8e132f04395d660ad3a0b13a736f7a;p=gnome-shell.git dateMenu: Only use nearest city when appropriate Since commit 784c0b7e4 we use the name of the nearest city rather than the weather station, as the latter tend to have unwieldy and weird names. However the nearest city may not be that near after all, in which case the result is again surprising. Address this by not using the nearest city name unconditionally, but only if it appears in the station name. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2468 --- diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index a10c6fcf4..ca9611f2d 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -397,6 +397,20 @@ class WeatherSection extends St.Button { layout.attach(label, 0, 0, 1, 1); } + _findBestLocationName(loc) { + const locName = loc.get_name(); + + if (loc.get_level() === GWeather.LocationLevel.CITY || + !loc.has_coords()) + return locName; + + const world = GWeather.Location.get_world(); + const city = world.find_nearest_city(...loc.get_coords()); + const cityName = city.get_name(); + + return locName.includes(cityName) ? cityName : locName; + } + _updateForecasts() { this._forecastGrid.destroy_all_children(); @@ -405,13 +419,8 @@ class WeatherSection extends St.Button { return; } - let info = this._weatherClient.info; - let loc = info.get_location(); - if (loc.get_level() !== GWeather.LocationLevel.CITY && loc.has_coords()) { - let world = GWeather.Location.get_world(); - loc = world.find_nearest_city(...loc.get_coords()); - } - this._titleLocation.text = loc.get_name(); + const { info } = this._weatherClient; + this._titleLocation.text = this._findBestLocationName(info.location); if (this._weatherClient.loading) { this._setStatusLabel(_("Loading…"));